home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Utils / IceBreaker / Source / CLI / IceBreaker.c next >
Encoding:
C/C++ Source or Header  |  1997-04-25  |  3.4 KB  |  122 lines

  1. /*
  2. ** ICE BREAKER (CLI VERSION) V1.0
  3. ** ------------------------------
  4. ** Author:    Paul Manias
  5. ** Date:      25 April 1997.
  6. ** Copyright: DreamWorld Productions 1997.
  7. ** Compile:   sc IceBreaker.c nolink
  8. **            PhxAss /IceAssembler.asm
  9. **            slink FROM lib:c.o,IceBreaker.o,/IceAssembler.o TO IceBreaker LIBRARY LIB:sc.lib,LIB:Amiga.lib
  10. **
  11. ** Doc:       This is the entry code for IceBreaker, it sets things up
  12. **            so that the assembler code is ready to intercept debug
  13. **            messages.  This particular version outputs to the CLI
  14. **            or whatever stdout has been redirected to.
  15. */
  16.  
  17. #include <proto/games.h>
  18. #include <proto/exec.h>
  19. #include <proto/dos.h>
  20. #include <dos/dos.h>
  21.  
  22. extern struct ExecBase *SysBase;
  23. extern struct GFXBase *GFXBase;
  24.  
  25. #define LVODEBUGMESSAGE -378
  26. #define LVOERRORMESSAGE -384
  27. #define LVOSTEPBACK     -390
  28.  
  29. extern ULONG (libDebugMessage)();
  30. extern ULONG (libErrorMessage)();
  31. extern ULONG (libStepBack)();
  32.  
  33. struct GMSBase *GMSBase;
  34. struct Task *maintask;
  35. struct Task *edittask = NULL;
  36.  
  37. BPTR conhandle=0;      /* Handle to output debug information */
  38.  
  39. /***************************** INITIALISATION CODE *********************************/
  40.  
  41. void mainroutine(void);
  42. long getlen(char string[]);
  43. void wtext(char string[]);
  44.  
  45. void main(void)
  46. {
  47.  void *oldDebugMessage;
  48.  void *oldErrorMessage;
  49.  void *oldStepBack;
  50.  
  51.  maintask = FindTask(0);
  52.  
  53.  if (GMSBase = (struct GMSBase *) OpenLibrary("GMS:GPI/Master.GPI",0)) {
  54.   if (GFXBase = (struct GFXBase *) OpenLibrary("graphics.library",0)) {
  55.    if (DebugActive() == ERR_OK) {
  56.     if (conhandle = Output()) {
  57.  
  58.        Forbid();
  59.        oldDebugMessage = SetFunction((struct Library *)GMSBase,LVODEBUGMESSAGE,&libDebugMessage);
  60.        oldErrorMessage = SetFunction((struct Library *)GMSBase,LVOERRORMESSAGE,&libErrorMessage);
  61.        oldStepBack     = SetFunction((struct Library *)GMSBase,LVOSTEPBACK,&libStepBack);
  62.        SumLibrary((struct Library *)GMSBase);
  63.        Permit();
  64.  
  65.        mainroutine();
  66.  
  67.        Forbid();
  68.        SetFunction((struct Library *)GMSBase,LVODEBUGMESSAGE,oldDebugMessage);
  69.        SetFunction((struct Library *)GMSBase,LVOERRORMESSAGE,oldErrorMessage);
  70.        SetFunction((struct Library *)GMSBase,LVOSTEPBACK,oldStepBack);
  71.        SumLibrary((struct Library *)GMSBase);
  72.        Permit();
  73.  
  74.     }
  75.    DebugInactive();
  76.    }
  77.   CloseLibrary((struct Library *)GFXBase);
  78.   }
  79.  CloseLibrary((struct Library *)GMSBase);
  80.  }
  81. }
  82.  
  83. /*********************************** MAIN LOOP *************************************/
  84.  
  85. void mainroutine(void)
  86. {
  87.   LONG result;
  88.  
  89.   wtext("\nWelcome to IceBreaker V1.0, the debugger for GMS programs.\n");
  90.   wtext("This program will wait until a program using GMS is executed.  Any\n");
  91.   wtext("debug messages that are sent while it is active will be intercepted\n");
  92.   wtext("and printed out to this window.\n\n");
  93.   wtext("Press CTRL-C at any time to exit.\n\n");
  94.   wtext("Type                 | Data\n");
  95.   wtext("---------------------+---------------------------------------------\n");
  96.  
  97.   do {
  98.      result = Wait(SIGBREAKF_CTRL_C);
  99.   } while (!(result & SIGBREAKF_CTRL_C));
  100.  
  101. }
  102.  
  103. /***********************************************************************************/
  104.  
  105. void wtext(char string[]) {
  106.   Write(conhandle,string,getlen(string));
  107. }
  108.  
  109. /***********************************************************************************/
  110.  
  111. long getlen(char string[])
  112. {
  113.   int length=0;
  114.  
  115.   while (string[length] != 0) {
  116.     length++;
  117.     if (length > 256) break;
  118.   }
  119.   return(length);
  120. }
  121.  
  122.